<#assign path = request.getContextPath() />
<!DOCTYPE html>
<html class="x-admin-sm">
    
    <head>
        <meta charset="UTF-8">
        <title>编辑</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="${path}/static/css/font.css">
        <link rel="stylesheet" href="${path}/static/css/css.css">
		<link rel="stylesheet" type="text/css" href="${path}/static/css/xadmin.css"/>
        <script type="text/javascript" src="${path}/static/lib/layui/layui.js"></script>
        <script type="text/javascript" src="${path}/static/js/xadmin.js"></script>
		<style>
			.layui-form-item .layui-input-inline{width: 290PX;}
		</style>
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" action="/addEmployee">
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <!-- <span class="x-red">*</span> -->
						  姓名
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="username" name="emp_name" required="" class="layui-input" value="${data.name}">
                      </div>
                  </div>
				   <div class="layui-form-item">
				      <label for="" class="layui-form-label">
				  		部门
				      </label>
				      <div class="layui-input-inline">
				  			<select name="dept_name">
				  				<option value="开发">开发</option>
								<option value="测试">测试</option>
				  			</select>
				      </div>
				  </div>
				  <div class="layui-form-item">
				      <label for="username" class="layui-form-label">
				  		性别
				      </label>
				      <div class="layui-input-inline">
				  			<select name="gender">
                                <#if data.gender == 1>
                                    <option value="1" selected>男</option>
                                <#else>
                                    <option value="2">女</option>
                                </#if>
				  			</select>
				      </div>
				  </div>
				   <div class="layui-form-item">
				      <label for="username" class="layui-form-label">
				  		岗位
				      </label>
				      <div class="layui-input-inline">
				  			<select name="post_name">
				  				<option value="开发">开发</option>
				  				<option value="测试">测试</option>
				  			</select>
				      </div>
				  </div>
				   <div class="layui-form-item">
				      <label for="username" class="layui-form-label">
				  		工种
				      </label>
				      <div class="layui-input-inline">
				  			<select name="job_name">
				  				<option value="领导">领导</option>
				  				<option value="工人">工人</option>
				  			</select>
				      </div>
				  </div>
				   <div class="layui-form-item">
				      <label for="username" class="layui-form-label">
				  		入职时间
				      </label>
				      <div class="layui-input-inline">
						   <input class="layui-input" placeholder="选择" name="hire_date" id="start">
				      </div>
				  </div>
				   <div class="layui-form-item">
				      <label for="username" class="layui-form-label">
				  		员工编号
				      </label>
				      <div class="layui-input-inline">
				          <input type="text" id="username" name="emp_no" required="" lay-verify="required"
				          autocomplete="off" class="layui-input" placeholder="必填" value="${data.empNo}">
				      </div>
				  </div>

                  <div class="layui-form-item">
                      <label for="phone" class="layui-form-label">
                         手机号
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="phone" name="phone" required="" lay-verify="phone"
                          autocomplete="off" class="layui-input" placeholder="必填" value="${data.mobile}">
                      </div>
                  </div>
                  <div class="layui-form-item">
                     <label for="phone" class="layui-form-label">
                        身份证号
                     </label>
                     <div class="layui-input-inline">
                         <input type="text" id="code" name="identity_no" required="" lay-verify=""
                         autocomplete="off" class="layui-input" maxlength="18" placeholder="必填" value="${data.identityNo}">
                     </div>
                  </div>
                  
                  <#--<div class="layui-form-item">-->
                      <#--<div class="layui-inline">-->
                          <#--<label for="L_repass" class="layui-form-label">-->
                              <#--照片-->
                          <#--</label>-->
                          <#--&lt;#&ndash;<input type="file" id="files" class="layui-btn" name="file"/>&ndash;&gt;-->
						  <#--<button type="button" id="files" class="layui-btn" name="file">-->
                              <#--<i class="layui-icon">&#xe67c;</i>上传图片-->
						  <#--</button>-->
                          <#--<p class="remark">支持格式jpg, 文件大小1M以内</p>-->
						  <#--<input type="text" name="photoId" id="photoId" class="layui-hide"/>-->
                      <#--</div>-->
                  <#--</div>-->
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label"></label>
                      <button  class="btn" lay-filter="keep" lay-submit="">保存</button>
                      <button  class=" btn-nobg" lay-filter="reset" lay-submit="reset">重置</button>
                  </div>
              </form>
            </div>
        </div>
        <script>
            layui.use(['laydate', 'form'],
                    function () {
                        var laydate = layui.laydate;

                        //执行一个laydate实例
                        laydate.render({
                            elem: '#start' //指定元素
                        });

                        //执行一个laydate实例
                        laydate.render({
                            elem: '#end' //指定元素
                        });
                    });


            layui.use(['form', 'layer'],
                    function () {
                        $ = layui.jquery;
                        var form = layui.form,
                                layer = layui.layer;

                        //自定义验证规则
                        form.verify({
                            nikename: function (value) {
                                if (value.length < 5) {
                                    return '昵称至少得5个字符啊';
                                }
                            },
                            pass: [/(.+){6,12}$/, '密码必须6到12位'],
                            repass: function (value) {
                                if ($('#L_pass').val() != $('#L_repass').val()) {
                                    return '两次密码不一致';
                                }
                            }
                        });

                        //监听提交
                        form.on('submit(keep)',
                                function (data) {
                                    console.log(data);
                                    var params = data.field;
                                    var empName = params.emp_name;
                                    var deptName = params.dept_name;
                                    var deptId = '212';
                                    var gender = params.gender;
                                    var postName = params.post_name;
                                    var postId = '343';
                                    var jobName = params.job_name;
                                    var jobId = '2323';
                                    var hireDate = params.hire_date;
                                    var empNo = params.emp_no;
                                    var mobile = params.phone;
                                    var identityNo = params.identity_no;
                                    var photoId = params.photoId;

                                    $.ajax({
                                        url: "/api/employee/edit",
                                        type: "POST",
                                        data: {
                                            name: empName,
                                            deptId: "1",
                                            deptName: deptName,
                                            empNo: empNo,
                                            mobile: mobile,
                                            gender: gender,
                                            identityNo: identityNo,
                                            hireDate: hireDate,
                                            jobId: "2",
                                            jobName: jobName,
                                            postId: '3',
                                            postName: postName,
											photoId: photoId,
                                        },
                                        success: function (data) {
                                            console.log(data);
                                            if (data.status == 200) {
                                                //发异步，把数据提交给php
                                                layer.msg("保存成功", {
                                                            icon: 6
                                                        },
                                                        function () {
                                                            //关闭当前frame
                                                            xadmin.close();
                                                            // 可以对父窗口进行刷新
                                                            xadmin.father_reload();
                                                        });
                                            }
                                        }
                                    });
                                    return false;
                                });

                        form.on('submit(reset)',
                                function (data) {
                                    console.log(data);
                                    //发异步，把数据提交给php
                                    layer.alert("重置成功", {
                                                icon: 6
                                            },
                                            function () {
                                                //关闭当前frame
                                                xadmin.close();

                                                // 可以对父窗口进行刷新
                                                xadmin.father_reload();
                                            });
                                    return false;
                                });
                    });

            //上传
            layui.use(['jquery', 'form','upload'], function () {
                var $ = layui.jquery,
						form=layui.form,
						upload=layui.upload;
                //执行实例
                upload.render({
                    elem: '#files',
                    url: '/api/employee/upload/single',
                    multiple: true,
					size:1024*1024,
					before: function (obj) {
                      layer.load();
					},
                    done: function (res) {
                        layer.closeAll('loading');
                        console.log(res);
                        if (res.status == 200) {
                            layer.msg("上传成功",{
                                icon: 6
							});
                            var imageId = res.datas;
                            $('#photoId').val(imageId);
						}

                    }
                    , error: function () {
                        layer.closeAll('loading');
                    }
                });
            });

        </script>
        
    </body>

</html>
